package controllers;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.h2.mvstore.DataUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Function;
import com.google.common.collect.Maps;

import models.DrCourtMonthModelVo;
import services.CourtStatisticService;
import services.DrCaseSortService;
import utils.DateUtil;
import vos.Node;

/**
 * 开庭统计类
 * @author Joker
 *
 */
public class CourtStatisticControllers extends BaseController{
	
	public static final Logger log=LoggerFactory.getLogger("courtStatistic");
	/**
	 * 近一个月内折线图
	 */
	public static void getMonthFoldLine(){
		Date now = DateUtil.now();
		Date lastMonth = DateUtil.formatDate(DateUtil.getLastMonth());
		List<DrCourtMonthModelVo> list = CourtStatisticService.getFoldLineByDate(now,lastMonth);
		//Map<Date, Integer> map = list.stream().collect(Collectors.toMap(DrCourtMonthModelVo::getStartCourtDate, DrCourtMonthModelVo::getStartCourtCount));
		Map<Date, Integer> map = new HashMap<Date, Integer>();
		for(DrCourtMonthModelVo drCourtMonthModelVo : list){
			map.put(drCourtMonthModelVo.getStartCourtDate(), drCourtMonthModelVo.getStartCourtCount());
		}
		List<String> times = new ArrayList<String>();
		List<Integer> values = new ArrayList<Integer>();
		for(Date date=lastMonth;DateUtil.getTomorrow().after(date);date = DateUtil.getNextDay(date,1)){
			times.add(DateUtil.fommatYMD(date));
			if(map.get(date) == null){
				values.add(0);
			}else{
				values.add(map.get(date));
			}
		}
		Map<String,Object> data = new HashMap<String,Object>();
		data.put("times", times);
		data.put("counts", values);
		renderJSON(data);
	}
	
	/**
	 * 近一个月内饼图
	 */
	public static void getMonthPieChart(){
		List<DrCourtMonthModelVo> list = CourtStatisticService.getMonthPieChartByDate(DateUtil.now(),DateUtil.formatDate(DateUtil.getLastMonth()));
		
		renderJSON(list);
	}

}
